package com.changgou.entity;

import lombok.Data;

/**
 * 返回结果实体类
 */
@Data
public class Result<T> {

    private boolean flag;//是否成功
    private Integer code;//返回码
    private String message;//返回消息

    private T data;//返回数据

    public Result(boolean flag, Integer code, String message, Object data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = (T)data;
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result() {
        this.flag = true;
        this.code = StatusCode.OK;
        this.message = "执行成功";
    }

    /**
 * @MethodName com.changgou.common.pojo.Result : Result
 * @Author Jiang YiLin
 * @Date 16:39  2019/11/11
 * @Param [resultCode, data]
 * @Return
 * @Description 使用枚举类型定义返回对象
 **/
    public Result(ResultCode resultCode, Object data) {
        this.flag = resultCode.success();
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = (T)data;
    }

    public Result(ResultCode resultCode) {
        this.flag = resultCode.success();
        this.code = resultCode.code();
        this.message = resultCode.message();
    }
}
